<?php

class dbaPaymentMode {

  function dbaPaymentMode (&$dba) {
    $this->dba = &$dba;
  }

  function add ($descr,$home,$abroad,$is_default,$amount,$percent,$tax){
    if (!$home)       $home       = 'N';
    if (!$abroad)     $abroad     = 'N';
    if (!$is_default) $is_default = 'N';
    return $this->dba->query("insert into ".$this->dba->tableforwarder."_shopPaymentMode (descr,home,abroad,is_default,amount,percent,tax) values ('$descr','$home','$abroad','$is_default','$amount','$percent','$tax');");
  }

  function getall ()
  {
    $this->dba->query("select * from ".$this->dba->tableforwarder."_shopPaymentMode;");
    return $this->dba->fetch_rows_Array();
  }

  function getByArea ($home,$abroad)
  {
     if ($home || $abroad) 
     {
       $where .= ' where ';
       if ($home == 'Y') 
       {
         $where .= "home ='$home' ";
         if ($abroad) $where .= 'AND ';
       }
       if ($abroad == 'Y') 
       {
         $where .= "abroad = '$abroad' ";
       }
     }
     if ($ordered)
     {
       $orderStr = ' order by name';
     }
    $this->dba->query("select * from ".$this->dba->tableforwarder."_shopPaymentMode$where;");
    return $this->dba->fetch_rows_Array();
  }

  function getByAreaLang ($home,$abroad, $lang_id)
  {
     if ($home || $abroad) 
     {
       $where .= ' where ';
       if ($home == 'Y') 
       {
         $where .= "home ='$home' ";
         if ($abroad) $where .= 'AND ';
       }
       if ($abroad == 'Y') 
       {
         $where .= "abroad = '$abroad' ";
       }
     }
     $where .= " and M.id=D.m_id and lang_id=$lang_id";
     if ($ordered)
     {
       $orderStr = ' order by name';
     }
    $this->dba->query("select M.id, D.descr, M.is_default from ".$this->dba->tableforwarder."_shopPaymentMode M, "
        .$this->dba->tableforwarder."_shopPaymentDescr D $where;");
    return $this->dba->fetch_rows_Array();
  }

  function get ($id){
    $this->dba->query("select * from ".$this->dba->tableforwarder."_shopPaymentMode where id = '$id';");
    return $this->dba->fetch_row_Array();
  }

  function updateWODescr ($id,$home,$abroad,$is_default,$amount,$percent,$tax) {
    if (!$home)       $home       = 'N';
    if (!$abroad)     $abroad     = 'N';
    if (!$is_default) $is_default = 'N';
    return $this->dba->query("update ".$this->dba->tableforwarder."_shopPaymentMode set home='$home',abroad='$abroad',is_default='$is_default',amount='$amount',percent='$percent',tax='$tax' where id ='$id';");
  }

  function update ($id,$descr,$home,$abroad,$is_default,$amount,$percent,$tax) {
    if (!$home)       $home       = 'N';
    if (!$abroad)     $abroad     = 'N';
    if (!$is_default) $is_default = 'N';
    return $this->dba->query("update ".$this->dba->tableforwarder."_shopPaymentMode set descr='$descr',home='$home',abroad='$abroad',is_default='$is_default',amount='$amount',percent='$percent',tax='$tax' where id ='$id';");
  }

  function del ($id) {
    return $this->dba->query("delete from ".$this->dba->tableforwarder."_shopPaymentMode where id = '$id';");
  }

}

?>